﻿'Option Explicit On
'Option Strict On
Imports System.IO

Public Class Form1
    Public miExplorador As New ExploradorCarpetas

#Region "Botones"
    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        ListView1.Items.Clear()
        TreeView1.Nodes.Clear()
        miExplorador.cargarCarpetas(TextBox1.Text)
        cargarArchivos(TextBox1.Text)
    End Sub

    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        ListView1.Items.Clear()
        TreeView1.Nodes.Clear()
        TextBox1.Text = "C:\Windows"
    End Sub
#End Region

#Region "Funciones y métodos"
    Private Sub cargarArchivos(ByVal ruta As String)
        Try
            For Each item In miExplorador.cargarArchivos(ruta)
                ListView1.Items.Add(item)
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString)
            Beep()
        End Try
    End Sub
#End Region

#Region "Eventos"

    Private Sub TreeView1_AfterExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterExpand
        Dim n As System.Windows.Forms.TreeNode
        For Each n In e.Node.Nodes
            miExplorador.cargarSubcarpetas(CStr(n.Tag), n)
        Next
    End Sub

    Public Sub TreeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
        ListView1.Items.Clear()
        cargarArchivos(CStr(e.Node.Tag))
    End Sub

#End Region

#Region "Load y otros"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Agregar columnas  
        With ListView1
            .Columns.Add("Nombre", 150)
            .Columns.Add("Fecha y hora de modificación", 150)
            .Columns.Add("Tamaño - bytes ", 100)
            .Columns.Add("Extensión", 80)
            .View = View.Details
            .GridLines = True
        End With
        btnBuscar.Text = "Listar propiedades"
        TextBox1.Text = "C:\Windows"
    End Sub

#End Region
End Class
